package org.finesys.common.redisson.service;

import org.finesys.common.redisson.constants.RedissonLockType;
import org.finesys.common.redisson.entity.LockEntity;

public interface RedissonService {

    ThreadLocal<LockEntity> THREAD_LOCK = new ThreadLocal<>();

    /**
     * 枷锁
     */
    boolean lock(LockEntity lockEntity);

    /**
     * 解锁
     */
    void unlock(LockEntity lockEntity);

    /**
     * 锁类型
     */
    RedissonLockType lockType();

    /**
     * 获取当前线程的锁
     */
    default LockEntity getThreadLock() {
        return THREAD_LOCK.get();
    }

    /**
     * 保存当前线程的锁
     */
    default void saveThreadLock(LockEntity lockEntity) {
        THREAD_LOCK.set(lockEntity);
    }

    /**
     * 清空当前线程的锁
     */
    default void clearThreadLock() {
        THREAD_LOCK.remove();
    }

}
